<template>
  <div>
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="user" placeholder="请输入内容"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="success">发布</el-button>
      </el-form-item>
    </el-form>
    <hr />
    <el-table
      :data="tableData"
      style="width: 100%"
    >
      <el-table-column prop="num" label="编号" width="100"> </el-table-column>
      <el-table-column prop="user" label="用户名" width="180">
      </el-table-column>
      <el-table-column prop="con" label="内容"> </el-table-column>
      <el-table-column fixed="right" label="操作" width="220">
        <template slot-scope="scope">
          <el-button
            @click.native.prevent="edit(scope.$index, tableData)"
            type="warning"
            size="small"
          >
            修改
          </el-button>
          <el-button
            @click.native.prevent="del(scope.$index, tableData)"
            type="danger"
            size="small"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      background
      layout="prev, pager, next"
      :page-size="5"
      :total="tableData.length"
    >
    </el-pagination>

    <!-- 编辑框 -->
    <el-dialog width="40%" title="内容编辑" :visible.sync="editBox">
      <el-form :model="editData">
        <el-form-item label="用户名" :label-width="100">
          <el-input disabled v-model="editData.user" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="内容" :label-width="100">
          <el-input v-model="editData.con" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="editBox = false">取 消</el-button>
        <el-button type="primary" @click="editBox = false"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      user: "",
      tableData: [
        {
          num: "1",
          user: "王小虎",
          con: "aaaaaaaaaaaa",
        },
        {
          num: "2",
          user: "王小虎1",
          con: "aaaaaaaaaaaa1",
        },
        {
          num: "3",
          user: "王小虎2",
          con: "aaaaaaaaaaaa2",
        },
        {
          num: "4",
          user: "王小虎",
          con: "aaaaaaaaaaaa",
        },
        {
          num: "5",
          user: "王小虎1",
          con: "aaaaaaaaaaaa1",
        },
        {
          num: "6",
          user: "王小虎2",
          con: "aaaaaaaaaaaa2",
        },
      ],
      editBox:false,
      editData:{
          num: "1",
          user: "王小虎",
          con: "aaaaaaaaaaaa",
        }
    };
  },
  methods: {
    edit() {
        this.editBox=true;
    },
    del() {
        this.$confirm('此操作将永久这条内容？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
    },
  },
};
</script>
<style scoped lang="less">
.el-pagination {
  margin-top: 20px;
  float: right;
}
</style>
